package com.example.teachingSystem.controller;

import com.example.teachingSystem.pojo.entity.Permission;
import com.example.teachingSystem.service.PermissionService;
import com.example.teachingSystem.utils.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/perm")
@Tag(name = "权限模块")
public class PermissionController {

    @Autowired
    private PermissionService permissionService;

    @PostMapping("/change/{id}")
    @Operation(summary = "开放权限", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> openSelectPerm(@PathVariable Long id) {
        return permissionService.changePermToOpen(id);
    }

    @PutMapping("/change/{id}")
    @Operation(summary = "关闭权限", security = {@SecurityRequirement(name = "Authorization")})
    public Result<String> closeSelectPerm(@PathVariable Long id) {
        return permissionService.changePermToClose(id);
    }

    @GetMapping("/more")
    @Operation(summary = "获取权限列表", security = {@SecurityRequirement(name = "Authorization")})
    public Result<List<Permission>> getPermission() {
        return permissionService.getPermission();
    }
}